<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import {loginApi} from '@/api/login'

//登录模块DOTO
const atuo = ref(false)
const remmend = ref(false)

//点击登录数据跳转页面
const route = useRouter()
const LoginData = ref({username: '', password: ''})
const loginsubmit = async() => {
    const result = await loginApi(LoginData.value)
    if(result.code){
        ElMessage.success(result.msg)
        localStorage.setItem('LoginUser',JSON.stringify(result.data))
        route.push('/')
    }else{
        ElMessage.error(result.msg)
    }
}
</script>

<template>
    <div class="body">
        <form @submit.prevent="loginsubmit">
            <div class="login-box">
                <h1>登录</h1>
                <div class="input-box">
                    <div class="input-text">
                        <span class="input-img1"><img src="../../assets/images/登录图标.png" alt=""></span>
                        <input v-model="LoginData.username" type="text" placeholder="用户名" name="" id="">
                    </div>
                    <div class="input-text">
                        <span class="input-img2"><img src="../../assets/images/密码.png" alt=""></span>
                        <input v-model="LoginData.password" type="password" placeholder="密码" name="" id="">
                    </div>
                    <div class="input-text">
                        <input type="password" style="width: 100px;" placeholder="验证码" name="" id=""><span
                            style="width: 100px;"></span>
                    </div>
                    <div class="input-text">
                        <el-checkbox v-model="atuo" label="自动登录" size="large" />
                        <el-checkbox v-model="remmend" label="记住密码" size="large" />
                    </div>
                    <div class="input-btn">
                        <span><input style="background: transparent; border: none; color: white;" type="submit"
                                value="登录进入后台"></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
</template>

<style scoped>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.body {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
    background-image: url(@/assets/images/登录页面.jpg);
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    overflow: hidden;
}

.sign-up-link {
    cursor: pointer;
    color: #3498db;
}

a {
    text-decoration: none;
    color: white;
}

.login-box {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    width: 600px;
    height: 500px;
    background-color: rgba(0, 0, 0, .5);
    border: 10px;
    padding: 20px 50px;
    border-radius: 20px;
}

.login-box h1 {
    width: 100%;
    display: flex;
    justify-content: center;
    color: #fff;
    font-size: 30px;
}

.login-box .input-box {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    transform: translateY(-35px);
}

.login-box .input-box .input-text {
    width: 100%;
    display: flex;
    justify-content: center;
}

.input-text .input-img1 img {
    position: absolute;
    top: 25px;
    left: 142px;
    height: 20px;
    width: 20px;

}

.input-text .input-img2 img {
    position: absolute;
    top: 76px;
    left: 142px;
    height: 20px;
    width: 20px;

}

.login-box .input-box .input-text input {
    border: 0;
    padding: 6px;
    border-bottom: 1px solid white;
    background-color: #ffffff00;
    color: #fff;
    margin-top: 20px;
}

.login-box .input-box .input-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.login-box .input-box .input-btn span {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 25px 15px 0px 15px;
    width: 145px;
    height: 25px;
    color: #fff;
    background: linear-gradient(123deg, #a6c0fe 0%, #f68084 100%);
    border-radius: 25px;
    cursor: pointer;
}

.login-box .input-box .sign-up {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 40px;
    color: white;
    font-size: 15px;
}

.login-box .input-box .sign-up a {
    color: #3498db;
    text-decoration: none;
}

.back-login {
    position: fixed;
    top: -40px;
    left: 0px;
}
</style>